{extend name="public/base" /}
{block name="css"}
<link rel="stylesheet" href="__INDEX__/css/create.css">
<link href="__PLUGIN__/Fileinput/css/fileinput.css" rel="stylesheet">
<style>
.col-sm-12{padding:0px;}
</style>
{/block}
{block name="container"}
<div class="panel-body panel-body-nopadding" style="padding-bottom:50px;">
    <div class="inforMain">新建客户</div>
    <form class="form-horizontal form-bordered" id="submitForm" action="" method="post" > 
        <div class="form-group">
            <div class="col-sm-2"></div>
            <label class="col-sm-1 control-label"><span>*</span>客户名称：</label>
            <div class="col-sm-2">
                <input type="text" class="form-control" placeholder="客户名称" name="pub[name]" value="{$data.name ?? ''}"  required>
            </div>
            <label class="col-sm-1 control-label"><span>*</span>联系电话：</label>
            <div class="col-sm-3" >
                <input type="text" class="form-control" placeholder="联系电话" name="pub[phone]" value="{$data.phone ?? ''}"  required>
            </div>
        </div>
        
        <div class="form-group">
            <div class="col-sm-2"></div>
            <label class="col-sm-1 control-label"><span>*</span>性&emsp;&emsp;别：</label>
            <div class="col-sm-2" >
                <input type="radio" value="1" name="pub[sex]" style="margin-top: 10px;margin-right: 8px;">男 
                <input type="radio" value="2" name="pub[sex]" style="margin-left:30px;margin-top: 10px;margin-right: 8px">女
            </div>
            <label class="col-sm-1 control-label"><span>*</span>年&emsp;&emsp;龄：</label>
            <div class="col-sm-3">
                <input type="text" class="form-control" placeholder="年龄" name="pub[age]" value="{$data.age ?? ''}"  >
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-2"></div>
            <label class="col-sm-1 control-label"><span>*</span>客户意向：</label>
            <div class="col-sm-2">
               <select name="pub[yixiang]" id="" class="form-control">
                 <option value="-1">--请选择--</option>
                 <option value="A">关键客户</option>
                 <option value="B">主要客户</option>
                 <option value="C">普通客户</option>
                 <option value="D">一般客户</option>
                 <option value="E">死客</option>
                 <option value="F">团购意向客户</option>
               </select>
            </div>
            
            <label class="col-sm-1 control-label"><span>*</span>客户级别：</label>
            <div class="col-sm-3">
                <select name="pub[level]" id="" class="form-control" >
                  <option value="-1">--请选择--</option>
                  {volist name="level" id="vo"}
                  <option value="{$vo.id}">{$vo.title}</option>
                  {/volist}
                </select>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-2"></div>
            <label class="col-sm-1 control-label"><span>*</span>客户行业：</label>
            <div class="col-sm-2">
              <input type="text" class="form-control" value="{$data.hangye ?? ''}" placeholder="客户行业" name="pub[hangye]">
            </div>
            <label class="col-sm-1 control-label"><span>*</span>客户来源：</label>
            <div class="col-sm-6" >
                <input type="radio" value="1" name="pub[from]" style="margin-top: 10px;margin-right: 5px;" required>个人查找
                <input type="radio" value="2" name="pub[from]" style="margin-left:30px;margin-top: 10px;margin-right: 5px" required> 进店客户
                <input type="radio" value="3" name="pub[from]" style="margin-left:30px;margin-top: 10px;margin-right: 5px" required>公司派单
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2"></div>
            <label class="col-sm-1 control-label"><span>*</span>地&emsp;&emsp;址：</label>
            <div class="col-sm-2">
                <select   name="pub[prov]" class="form-control" id="province" onchange="getRegion(this.value,1)">
                    <option value="-1">省份</option>
                    {volist name="prov" id="vo"}
                    <option value="{$vo.code}">{$vo.name}</option>
                    {/volist}
                </select>
            </div>
            <div class="col-sm-2">
                <select  name="pub[city]" id="city" class="form-control" onchange="getRegion(this.value,2)">
                    <option value="-1">城市</option>
                    {if condition="$Request.action eq 'privateupdate'"}
                      {volist name="city" id="vo"}
                      <option value="{$vo.code}">{$vo.name}</option>
                      {/volist}
                    {/if}
                </select>
            </div>
            <div class="col-sm-2">
                <select name="pub[area]" class="form-control" id="area">
                    <option value="-1">县/区</option>
                     {if condition="$Request.action eq 'privateupdate'"}
                      {volist name="area" id="vo"}
                      <option value="{$vo.code}">{$vo.name}</option>
                      {/volist}
                    {/if}
                </select>
            </div>        
        </div>
        <div class="form-group">
            <div class="col-sm-2"></div>
            <label class="col-sm-1 control-label"><span>*</span>详细地址：</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" placeholder="详细地址" name="pub[address]" value="{$data.address ?? ''}"  required>
            </div>
        </div>

        <div class="form-group">
          <div class="col-sm-2"></div>
          <label class="col-sm-1 control-label"><span>*</span>备&emsp;&emsp;注</label>
          <div class="col-sm-6">
            <textarea name="pub[content]" id="" cols="30" rows="10" style="width: 100%;outline: none;resize: none;">{$data.content ?? ''}</textarea>
          </div>
        </div>
        
        <div class="form-group">
            <div class="col-sm-2"></div>
            <div class="dianji_box" style="padding-left: 50px;cursor: pointer;color: #F56A6F;">点击填写客户公司信息</div>
        </div>
        <div class="companyBox" style="display: none;height: 130px;">
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label class="col-sm-1 control-label">公司名称：</label>
                <div class="col-sm-2">
                  <input type="text" class="form-control" placeholder="客户公司名称" name="comp[name]" value="{$comp.name ?? ''}">
                </div>    

                <label class="col-sm-1 control-label">公司电话：</label>
                <div class="col-sm-3">
                  <input type="text" class="form-control" placeholder="客户公司电话" name="comp[phone]" value="{$comp.phone ?? ''}">
                </div>    
            </div>

            <div class="form-group">
              <div class="col-sm-2"></div>
              <label class="col-sm-1 control-label">公司地址：</label>
              <div class="col-sm-6">
                <input type="text" placeholder="客户公司地址" class="form-control" name="comp[address]" value="{$comp.address ?? ''}">
              </div>
            </div>

            <div class="form-group">
              <div class="col-sm-2"></div>
              <label class="col-sm-1 control-label">公司行业：</label>
              <div class="col-sm-2">
                <input type="text" placeholder="客户公司行业" class="form-control" name="comp[hangye]" value="{$comp.hangye ?? ''}">
              </div>
              
              <label class="col-sm-1 control-label">邮政编码：</label>
              <div class="col-sm-3">
                <input type="text" placeholder="请输入客户公司所在地邮政编码" class="form-control" name="comp[code]" value="{$comp.code ?? ''}">
              </div>
            </div>
        </div>
        
        
        
        
<div class="panel-footer">
  <div class="row">
   <div class="col-sm-6 col-sm-offset-3">
    {if condition="$Request.action eq 'privateupdate'"}
     <input type="hidden" name="comp_id" value="{$comp.id ?? ''}">
    {/if}
     <button type="submit" class="btn btn-primary" style="display: block;margin:0 auto">提交</button>
     <!--  <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);" style="margin:0 auto">返回</button> -->
 </div>
</div>
</div><!-- panel-footer --> 
</form>
</div>
{/block}
{block name="js"}
<script>
  $(document).ready(function(){
    $('.dianji_box').click(function(){
      $('.companyBox').slideToggle('slow');
      $('.companyBox').css('display','block');

    })
  })
</script>
<script>
  $(function(){
    $("[name='pub[yixiang]']").find("[value='{$data.yixiang ?? '-1'}']").attr("selected", true);
    $("[name='pub[level]']").find("[value='{$data.level ?? '-1'}']").attr("selected", true);
    $("[name='pub[prov]']").find("[value='{$data.prov ?? '-1'}']").attr("selected", true);
    $("[name='pub[city]']").find("[value='{$data.city ?? '-1'}']").attr("selected", true);
    $("[name='pub[area]']").find("[value='{$data.area ?? '-1'}']").attr("selected", true);
    $("[name='pub[from]'][value='{$data.from ?? '1'}']").attr("checked", true);
    $("[name='pub[sex]'][value='{$data.sex ?? '1'}']").attr("checked", true);
  }); 
</script>
 <script>
    function getRegion(val,level)
    {
      var $city = $("#city");
      var $area = $("#area");
      if(level=='1'){
        $city.html('<option value=""> --请选择市-- </option>');
        $city.val('');
    }
    $area.html('<option value=""> --请选择区-- </option>');
    $area.val('');
    $.post('{:url('index/common/getRegion')}', { pcode: val,level:level}, function(data) {
               var dataObj=eval("("+data+")");  
               if(dataObj['code']==1){
                if(level=='1'){
                    $.each(dataObj['list'], function(i, item) {
                      $city.append('<option value="'+item['code']+'">'+item['name']+'</option>');
                  });
                }else{
                    $.each(dataObj['list'], function(i, item) {
                      $area.append('<option value="'+item['code']+'">'+item['name']+'</option>');
                  });
                }
            }
        });
}
</script> 
{/block}